package topt

import (
	"fmt"
	"go_auth/ext/e"
	"go_auth/ext/settings"
	"go_auth/utils/commons"
	"go_auth/utils/redis"
)

func CheckCodeIsOk(user, code string) (bool, int) {

	value, err := redis.GetValue(user, settings.RDb5)
	if !commons.CheckErr(err) {
		return false, e.UserIdGetFailed
	}

	if len(code) != 6 {
		return false, e.ParamsError
	}

	if code == fmt.Sprint(ReturnCode(value)) {
		return true, e.Success
	}

	return false, e.CheckCodeError
}
